package com.csyf.manager.dao;

import com.csyf.manager.entity.SysPayment;

public class PaymentSqlProvider {

    public String sumPaymentFee(SysPayment vo) {

        StringBuffer sql = new StringBuffer("SELECT IFNULL(SUM(IFNULL(transmoney,0)),0) FROM sys_payment WHERE 1=1");
//        if(null != vo.getAgentId()){
//            sql.append(" AND agent_id = #{agentId}");
//        }
        if(null != vo.getMchId() && vo.getMchId() != ""){
            sql.append(" AND mch_id = #{mchId}");
        }
        if(null != vo.getSrcMchId() && vo.getSrcMchId() != ""){
            sql.append(" AND src_mch_id = #{srcMchId}");
        }
        if(null != vo.getOutTradeNo() && vo.getOutTradeNo() != ""){
            sql.append(" AND out_trade_no = #{outTradeNo}");
        }
        if(null != vo.getService() && vo.getService() != ""){
            sql.append(" AND service = #{service}");
        }
        if(null != vo.getPayType() && vo.getPayType() != ""){
            sql.append(" AND pay_type = #{payType}");
        }
        if(null != vo.getPayStatus() && vo.getPayStatus() != ""){
            sql.append(" AND pay_status = #{payStatus}");
        }
        if(null != vo.getCreateTimeString() && vo.getCreateTimeString() != ""
                && null != vo.getEndTimeString() && vo.getEndTimeString() != "") {
            sql.append(" AND create_time BETWEEN CONCAT(#{createTimeString},' 00:00:00') AND CONCAT(#{endTimeString},' 23:59:59')");
        }
        return sql.toString();
    }
}
